package com.china08.yxyapi.api.home.activity.lecture;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.entity.db.huodong.YxyHuodongLectureSchoolStatistics;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.statistics.YxyHuodongLectureSchoolStatisticsRepository;

@RestController
@CrossOrigin
public class ActivityLectureSchoolListController {

    @Autowired
    private YxyHuodongLectureSchoolStatisticsRepository yxyLectureRepository;

    @RequestMapping(value = "/api_yw/home/activity/tea/lecture/school/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> process(@RequestParam(value = "code") String code) {
        List<RespModel> list = new ArrayList<ActivityLectureSchoolListController.RespModel>();
        RespModel respModel = null;

        List<YxyHuodongLectureSchoolStatistics> list1 = yxyLectureRepository
                .findByAreaIdDistrictOrderByPackCountDesc(code.trim());

        for (YxyHuodongLectureSchoolStatistics yxy : list1) {
            respModel = new RespModel();
            respModel.setAddress(yxy.getAddress());
            respModel.setName(yxy.getSchoolNick());
            respModel.setNum(yxy.getPackCount());
            list.add(respModel);
        }
        return list;
    }

    protected static class ReqModel extends YxyApiReqModel {
    }

    protected static class RespModel extends YxyApiRespModel {
        public String name;
        public String address;
        public Long num;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getAddress() {
            return address;
        }

        public void setAddress(String address) {
            this.address = address;
        }

        public Long getNum() {
            return num;
        }

        public void setNum(Long num) {
            this.num = num;
        }

    }

}
